package cn.wolfcode.web.controller;

import cn.wolfcode.domain.File;
import cn.wolfcode.domain.User;
import cn.wolfcode.service.IFileService;
import cn.wolfcode.service.IUserService;
import cn.wolfcode.service.Impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
public class dengluController {
    @Autowired
    private IUserService userService;

    //IUserService userService = new UserServiceImpl();
    @RequestMapping("/denglu")
    public ModelAndView denglu(String username, String password, String denglu, HttpServletRequest request){
        ModelAndView mv = new ModelAndView();
        System.out.println(denglu);
        System.out.println(username);
        System.out.println(password);
        if("登录".equals(denglu)){
            User u1=userService.selectu(username);
            if(u1!=null){
                User u2=userService.selectup(username,password);
                if(u2!=null){
                    System.out.println(u2);
                    mv.addObject("username",username);
                    request.getSession().setAttribute("username",username);
                    Long uid = u2.getId();
                    System.out.println(uid);
                    mv.addObject("uid",uid);
                    request.getSession().setAttribute("uid",uid);
                    mv.setViewName("forward:/chaxunServlet/list");
                    return mv;
                }else {
                    mv.addObject("errorMsg", "密码错误");
                    mv.setViewName("forward:/static/index.jsp");
                    System.out.println("密码错误");
                }
            }else {
                mv.addObject("errorMsg", "没有该账号");
                mv.setViewName("forward:/static/index.jsp");
                System.out.println("没有该账号");

            }
        }else {

            mv.setViewName("zhuce");
        }
        return mv;
    }

}
